﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NguyenQuangKhanh_785255
{
    public partial class Main : Form
    {
        QueryString obj = new QueryString();
        public Main()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                cbo_OrderID.DataSource = obj.ShowOrder();
                cbo_OrderID.DisplayMember = "OrderID";
                cbo_OrderID.ValueMember = "OrderID";
            }catch{}
        }

        private void cbo_OrderID_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                foreach (DataRow row in obj.ShowOrder(cbo_OrderID.Text).Rows)
                {
                    txt_Date.Text = (string) row["OrderDate"];
                    txt_CustomerName.Text = (string) row["Name"];
                }
                dtg_ProductDetail.DataSource = obj.ShowOrderDeTail(cbo_OrderID.Text);
                double a = 0;
                double b = 0;
                for (int i = 0; i < dtg_ProductDetail.RowCount - 1; i++)
                {
                    a += double.Parse(dtg_ProductDetail.Rows[i].Cells["Quantity"].Value.ToString());
                    b += double.Parse(dtg_ProductDetail.Rows[i].Cells["Amount"].Value.ToString());
                }
                lbQuantity.Text = a.ToString();
                lbAmount.Text = "$" + b;
            }catch{}
        }
    }
}
